package com.zhou.project.modules.activity.activity.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.project.components.base.service.BaseService;
import com.zhou.project.modules.activity.activity.dao.ActivityDao;
import com.zhou.project.modules.activity.activity.entity.Activity;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
@CacheConfig(cacheNames = "activity")
public class ActivityService extends BaseService<ActivityDao, Activity> {


    @Cacheable(key = "'page:'+#entity.size+':'+#entity.current")
    public Page<Activity> page(Activity entity){

        Page<Activity> page =Page.of(entity.getCurrent(),entity.getSize());
        QueryWrapper<Activity> wrapper =new QueryWrapper<>();
        if (StringUtils.hasLength(entity.getName()))
            wrapper.like("name",entity.getName());
        if (entity.getUniversityId()!=null &&entity.getUniversityId()>0)
            wrapper.eq("universityId",entity.getUniversityId());
        return baseMapper.selectPage(page,wrapper);
    }

}
